<?php
require 'inc_security.php';
$catBase = new Category;
$lin_cat_id = array();
$arrCat = $catBase->list_categories(0,'cat_active = 1 AND cat_type="system"','cat_id,cat_name,cat_type','cat_id ASC');
foreach($arrCat as $i=>$cat){
    $tt = '';
    for($j=0;$j<$cat["level"];$j++) $tt .= '|--';
    $lin_cat_id[$cat["cat_id"]] = $tt . $cat["cat_name"];
}
$arr_site_type = array('other'=>'-- Chọn 1 loại --',
                        'wordpress'=>'Site wordpress',
                        'xenforo'=>'Site xenforo');
                          
$list = new dataGrid('lin_id',30);
$list->add('lin_title','Tên link','string',1,1, 'width="120px"');
$list->add('lin_cat_id','Danh mục','array',1,1);
$list->add('lin_site_type','Danh mục','array',1,1);
$list->add('lin_age','Tuổi site','int',1,1);
$list->add('lin_pr','Page rank','int',1,1);
$list->add('','Active','string');
$list->add('','Edit','edit');
$list->add('','Delete','delete');
$db_count = new db_count('SELECT count(*) as count 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ');
$total = $db_count->total;unset($db_count);

$db_listing = new db_query('SELECT * 
                            FROM '.$bg_table.'
                            WHERE 1 '.$list->sqlSearch().'
                            ORDER BY '.$list->sqlSort().' lin_id DESC
                            '.$list->limit($total));
$total_row = mysql_num_rows($db_listing->result);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?=$list->showHeader($total_row)?>
    <?php
    $i = 0; 
    ?>
    <?php while($row = mysql_fetch_assoc($db_listing->result)){
        $i++;
    ?>
    <?=$list->start_tr($i,$row[$id_field])?>
    <td>
        <div class="row">
            <div class="span1">Tên</div>
            <div class="span3"><?=form_input('lin_title'.$row[$id_field],$row['lin_title'],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></div>
        </div>
        <div class="row">
            <div class="span1">Link</div>
            <div class="span3"><?=form_input('lin_link'.$row[$id_field],$row['lin_link'],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></div>
        </div>
    </td>
    <td>Danh mục : <?=form_dropdown('lin_cat_id'.$row[$id_field],$lin_cat_id,$row['lin_cat_id'],'onchange="check_edit(\'record_'.$i.'\')"')?></td>
    <td>Danh mục : <?=form_dropdown('lin_site_type'.$row[$id_field],$arr_site_type,$row['lin_site_type'],'onchange="check_edit(\'record_'.$i.'\')"')?></td>
    <td>Tuổi : <?=form_input('lin_age'.$row[$id_field],$row['lin_age'],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></td>
    <td>Pr : <?=form_input('lin_pr'.$row[$id_field],$row['lin_pr'],'class="span3" onkeyup="check_edit(\'record_'.$i.'\')"')?></td>
    <?=$list->showCheckbox('lin_active',$row['lin_active'],$row[$id_field])?>
    <?=$list->showEdit($row[$id_field])?>
    <?=$list->showDelete($row[$id_field])?>
    <?=$list->end_tr()?>
    <?}?>
    <?=$list->showFooter()?>
</div>
</body>
</html>